<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 生成器就是一个特殊的函数
    // 为了实现异步编程 纯回调函数
    // yield是函数分割符
    /* 
    function* gen() {
      console.log('123');
    }
    gen().next() 
    */

    /*  function* gen() {
      yield '1235';
      yield '1234';
      yield '1235';
      yield '1236';
    }
    let s = gen()
    console.log(s.next());
    console.log(s.next());
    console.log(s.next());
    console.log(s.next());
 */
    // 传入参数
    function* gen(arg) {
      console.log(arg);
      let one = yield '12';
      console.log(one);
      let two = yield '123';
      console.log(two);
      let three = yield '1234';
      console.log(three);
      let four = yield '12345';
      console.log(four);
    }
    let s = gen('aa')
    console.log(s.next());
    // 第二次next传入的参数将作为第一个yield语句返回的结果，以此类推
    console.log(s.next('bb'));
    console.log(s.next('cc'));
    console.log(s.next('dd'));
  </script>
</body>

</html>